package cn.zhl.lambda;

import org.junit.Before;
import org.junit.Test;

import java.util.Arrays;
import java.util.List;
import java.util.function.Predicate;
import java.util.stream.Collectors;

/**
 * @program: demos
 * @description:
 * @author: 刘振华
 * @create: 2020-04-21 15:32
 **/
public class PredicateTest {
	List<Integer> list = null;

	@Before
	public void init() {
		list = Arrays.asList(3, 6, 8, 1, 2, 6, 9, 4, 0);
	}

	@Test
	public void test1() {
		List<Integer> is = get(list, i -> i > 5, i -> i % 2 == 0);
		is.stream().forEach(System.out::println);
	}

	public List<Integer> get(List<Integer> list, Predicate<Integer> pres, Predicate<Integer> pre) {
		return list.stream().filter(pre.and(pres)).collect(Collectors.toList());
	}

	@Test
	public void test2() {
		Predicate<Object> abc = Predicate.isEqual("abc");
		boolean abc1 = abc.test("abc");
		System.out.println(abc1);
	}

}
